package me.jessyan.armscomponent.app.mvp.ui.activity.mine;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.integration.AppManager;
import com.jess.arms.utils.ArmsUtils;

import org.jetbrains.annotations.NotNull;

import androidx.appcompat.app.AlertDialog;
import butterknife.OnClick;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.di.component.DaggerMineSettingComponent;
import me.jessyan.armscomponent.app.mvp.contract.mine.MineSettingContract;
import me.jessyan.armscomponent.app.mvp.presenter.mine.MineSettingPresenter;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.Utils;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * <p>
 * Author: Taozebi
 * Date: 08/08/2021 17:59
 * Description: 个人中心-设置
 */

@Route(path = RouterHub.MINE_SETTINGACTIVITY)
public class MineSettingActivity extends BaseActivity<MineSettingPresenter> implements MineSettingContract.View {


    @Override
    public void setupActivityComponent(@NotNull @NonNull AppComponent appComponent) {
        DaggerMineSettingComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }


    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.mine_activity_setting; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        loadTitle();
    }


    private void loadTitle() {
        setTitle("设置");
    }
    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @OnClick({R.id.mine_rl_set_userinfo,R.id.mine_rl_security_center,R.id.mine_rl_privacy_settings,R.id.mine_rl_about_us, R.id.mine_rl_quit})
    public void onClicked(View view){
        int id = view.getId();
        if(id == R.id.mine_rl_set_userinfo){
            if(Utils.isFastClick()){
                ARouter.getInstance().build(RouterHub.MINE_SETUSERINFOACTIVITY).navigation();
            }
        }else if(id == R.id.mine_rl_security_center){
            if(Utils.isFastClick()){
                ARouter.getInstance().build(RouterHub.MINE_SECURITYCENTERACTIVITY).navigation();
            }
        }else if(id == R.id.mine_rl_privacy_settings){
            if(Utils.isFastClick()){
                showMessage("隐私设置");
            }
        }else if(id == R.id.mine_rl_about_us){
            if(Utils.isFastClick()){
                showMessage("关于我们");
            }
        }else if(id == R.id.mine_rl_quit) {
//            CustomDialog customDialog = new CustomDialog(this);
//            customDialog.builder().setTitle("确定退出？").setPositiveButton(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    AppManager.getAppManager().appExit();
//                }
//            });
//            customDialog.show();
            showExitDialog();
        }
    }

    private void showExitDialog(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("系统提示")
                .setCancelable(false)
                .setMessage("确定退出当前程序~")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        AppManager.getAppManager().appExit();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .create().show();
    }
}
